Skip to content

[CI Visibility] Fix message loss and abandoned mutexes in the IPC channel - #9335

Merged
tonyredondo merged 5 commits into
masterfrom
tony/ci-visibility-ipc-cross-runtime-lock
Oct 28, 2026
Merged

tonyredondo merged 5 commits into
masterfrom
tony/ci-visibility-ipc-cross-runtime-lock

Conversation

@tonyredondo

@tonyredondo tonyredondo commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Summary of changes

Fixes four bugs in the CI Visibility IPC channel (CircularChannel) that lose messages or leave the channel locked:

  • Opening a channel reset its read and write pointers, so every new IPC client dropped the messages the other side hadn't read yet.
  • A completely full buffer was marked with a virtual write position that overflows the ushort pointer with the default 64 KB buffer. The reader then re-read the same messages forever while holding the lock, until the process ran out of memory.
  • The constructor and the writer let AbandonedMutexException escape. An abandoned wait still transfers ownership, so the thread kept the mutex and every other process using the channel timed out. The reader already handled this ([Test Optimization] Fix MSTest 4.4.0 discovery and native retries #9192).
  • Disposing a reader dropped whatever was written during its last polling interval.

Reason for change

Coverage results, session tags and the executed test count in #9486 all go through this channel, and each of these bugs can lose them. The abandoned-mutex one is the TODO that #9317 left in CheckBuildLogsForErrors.

Implementation details

  • The constructor only initializes the file (size and pointers) when it's new or has an unexpected size.
  • The writer always leaves one byte free, so the write position never reaches the read position and the virtual position is never written. Reader and writer still understand a virtual position written by an older version.
  • The constructor, writer and reader share TryAcquireMutex, which treats an abandoned mutex as acquired and logs a warning. Callers release it as usual. The CheckBuildLogsForErrors TODO and its ignore patterns for these errors are removed. The pattern for ReleaseMutex failing after a successful wait stays, with a new comment: that one comes from the .NET 11 RC runtime bug below, and it shows up on Linux ARM64 when a .NET 8-10 test host shares a channel with the .NET 11 VSTest runner.
  • The reader waits on its stop event instead of sleeping, so Dispose wakes it right away, and it polls once more before it stops. Dispose already joins the polling thread before the channel releases the memory mapped file.

This PR doesn't fix the .NET 11 RC named mutex incompatibility with .NET 8-10 on Unix (dotnet/runtime#134491). That's fixed in the runtime for .NET 11 GA (dotnet/runtime#134595), so the existing .NET 11 test skips stay until we move to GA. An earlier version of this PR replaced the named mutex with a file lock on Unix; I dropped it so we don't maintain a separate lock for a runtime bug that's going away.

Test coverage

New CircularChannelTests, each checked locally to fail without its fix:

  • OpeningAnExistingChannelKeepsUnreadMessages
  • BufferNeverFillsCompletelyWithTheDefaultSize: with the default buffer size, a message that would fill the buffer exactly is rejected, and every message is delivered exactly once. The unit tests used an 8 KB buffer, which never overflows.
  • OpeningAChannelAndWritingAcquireAnAbandonedMutex
  • DisposingAReaderReadsMessagesWrittenBeforeIt

CircularChannelWriteTest now expects one byte to stay free. Datadog.Trace.Tests.Ci.Ipc passes locally on Linux with net8.0.

Other details

Related: #9317, #9327, dotnet/runtime#134491, dotnet/runtime#134595. #9486 is stacked on this PR.

@tonyredondo
tonyredondo force-pushed the tony/ci-visibility-ipc-cross-runtime-lock branch from 6ff2985 to 8fc4f00 Compare September 30, 2026 11:55
@tonyredondo
tonyredondo marked this pull request as ready for review September 30, 2026 12:07
@tonyredondo
tonyredondo requested review from a team as code owners September 30, 2026 12:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T11:13:47.332848Z 1e14acd Manual request
🔒 Security Review ✅ Completed 2026-10-23T11:11:34.524706Z 1e14acd Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pr-commenter

pr-commenter Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-10-27 14:06:36

Comparing candidate commit ea54312 in PR branch tony/ci-visibility-ipc-cross-runtime-lock with baseline commit 0ac1395 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 71 metrics, 1 unstable metrics, 5 known flaky benchmarks, 121 flaky benchmarks without significant changes.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:Benchmarks.Trace.HttpClientBenchmark.SendAsync netcoreapp3.1

  • unstable execution_time [-29.514ms; -8.481ms] or [-14.725%; -4.232%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • unstable execution_time [-26.425ms; +66.730ms] or [-4.942%; +12.479%]
  • unstable throughput [+27.769op/s; +91.644op/s] or [+5.642%; +18.621%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • unstable execution_time [+20.666ms; +80.834ms] or [+4.542%; +17.766%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1

  • 🟥 allocated_mem [+15.763KB; +15.783KB] or [+6.109%; +6.117%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • unstable execution_time [-5.598µs; +0.874µs] or [-9.799%; +1.529%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark netcoreapp3.1

  • unstable execution_time [-1.485µs; +6.393µs] or [-2.736%; +11.782%]

Known flaky benchmarks without significant changes:

  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.ActivityBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_AddEvent_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_GetContext_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_RecordException_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetAttributes_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_SetStatus_Sampled netcoreapp3.1
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net472
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled net6.0
  • scenario:Benchmarks.OpenTelemetry.InstrumentedApi.Trace.TelemetrySpanBenchmark.StartSpan_UpdateName_Sampled netcoreapp3.1
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1
  • scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472
  • scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
  • scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472
  • scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472
  • scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1
  • scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472
  • scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0
  • scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1
  • scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472
  • scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net6.0
  • scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1
  • scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472
  • scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0
  • scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1
  • scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472
  • scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0
  • scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472
  • scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net6.0
  • scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1
  • scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net6.0
  • scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472
  • scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0
  • scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net6.0
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net6.0
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

@dd-trace-dotnet-ci-bot

dd-trace-dotnet-ci-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (9335) and master.

✅ No regressions detected

📄 View the full report (charts + all metrics) →

@tonyredondo
tonyredondo force-pushed the tony/ci-visibility-ipc-cross-runtime-lock branch from 8fc4f00 to ebb8189 Compare September 30, 2026 16:28
@tonyredondo
tonyredondo force-pushed the tony/ci-visibility-ipc-cross-runtime-lock branch from ebb8189 to 1e14acd Compare October 23, 2026 10:42
@andrewlock

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 1e14acdcb5

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e14acdcb5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@tonyredondo
tonyredondo force-pushed the tony/ci-visibility-ipc-cross-runtime-lock branch from 1e14acd to bf0693b Compare October 23, 2026 12:05
@tonyredondo tonyredondo changed the title [CI Visibility] Use a cross-runtime file lock for the IPC channel on Unix [CI Visibility] Fix message loss and abandoned mutexes in the IPC channel Oct 23, 2026
Opening a CircularChannel reset its read and write pointers, so every new
IPC client dropped the messages the other side hadn't read yet. Only a new
file, or one with an unexpected size, is initialized now.
A completely full buffer was marked with a virtual write position
(BufferBodySize + writePos), which overflows the ushort pointer with the
default 64 KB buffer. The reader then looped over the same messages forever
while holding the lock, until the process ran out of memory. Always keep
one byte free instead, so the write position never reaches the read position.
@tonyredondo
tonyredondo force-pushed the tony/ci-visibility-ipc-cross-runtime-lock branch from bf0693b to a84c18a Compare October 23, 2026 13:38
…or writing

WaitOne grants ownership of an abandoned mutex before it throws
AbandonedMutexException. The CircularChannel reader already handled that,
but the constructor and the writer let the exception escape, so the call
failed and the thread kept owning the mutex, which blocked every other
process using the channel. All three paths now share the reader's handling.

This resolves the TODO in CheckBuildLogsForErrors, so the ignore patterns
for those errors are removed. The pattern for ReleaseMutex failing after a
successful wait stays: that one comes from the .NET 11 RC named mutex bug
(dotnet/runtime#134491) and goes away with .NET 11 GA.
The reader slept between polls and returned early once the reader or the
channel was disposed, so anything written during its last polling
interval was dropped. A session that disposes its IPC server right after
the last message from a child process could lose that message.

The reader now waits on the stop event instead of sleeping, so Dispose
wakes it right away, and it polls once more before it stops. Dispose
already joins the polling thread before the channel releases the memory
mapped file.
@tonyredondo
tonyredondo force-pushed the tony/ci-visibility-ipc-cross-runtime-lock branch from a84c18a to 94750e5 Compare October 23, 2026 15:16
@tonyredondo
tonyredondo merged commit c263eee into master Oct 28, 2026
148 checks passed
@tonyredondo
tonyredondo deleted the tony/ci-visibility-ipc-cross-runtime-lock branch October 28, 2026 13:48
@github-actions github-actions Bot added this to the vNext-v3 milestone Oct 28, 2026
tonyredondo added a commit that referenced this pull request Oct 29, 2026
…ped (#9486)

## Summary of changes

When VSTest runs no tests and the run succeeds, the test session is now
reported as skipped:

- `test.status:skip`
- `test.skip_reason:No tests were executed`
- `test.session.empty_reason:zero_tests`

This is what you get from a filter that matches nothing, with `dotnet
test`, `dotnet vstest` or `vstest.console`. Sessions that ran tests, and
failed sessions, are reported as before. The tag, value and skip reason
are the same as in the Go version (DataDog/dd-trace-go#5697) and
datadog-ci-rb; dd-trace-js uses the same tag and value.

This is an alternative to #9325. It relies on the IPC channel fixes from
#9335.

## Reason for change

An empty run that exits successfully was reported as `pass`, so it
looked the same as a session whose test events were lost.

## Implementation details

- A new CallTarget integration hooks vstest.console's
`RunTestsArgumentExecutor+TestRunRequestEventsRegistrar.TestRunRequest_OnRunCompletion`,
the handler VSTest uses to print "No test matches the given testcase
filter". Its signature hasn't changed from vstest 15.9 to today, and it
only runs for command-line runs, so IDE (design mode) runs aren't
affected. The count comes from VSTest itself, which means it includes
tests from frameworks we don't instrument, and a session without test
events can't be mistaken for an empty one. An aborted, canceled or
failed run, or one without statistics, counts as unknown.
- vstest.console sends the count to the session it inherited the context
from, as a new `SessionExecutedTestsMessage` on the session's existing
IPC channel. That session lives in vstest.console itself (`dotnet
vstest`, `vstest.console`, and `dotnet test` on SDK 10 and later) or in
the `dotnet` CLI process (`dotnet test` on SDK 9 and earlier). Only
sessions created by the dotnet test integrations host the IPC server, so
manual sessions never get a count.
- `TestSession` keeps one small state: nothing reported, every report
was zero, or a runner ran tests or couldn't count them. A session that
closes as passed with only zero reports closes as skipped. The check
runs after the IPC server is disposed, so every report already sent has
been read. A runner exception counts as unknown, since CallTarget passes
exit code 0 in that case.
- The count travels over the session's IPC channel, so this needs the
`CircularChannel` fixes in #9335: a new client no longer drops the
session's unread messages, the reader reads what was written before it's
disposed, and an abandoned mutex no longer leaves the channel locked.
- Test modules that report to a session in another process also send how
many tests they created when they close, with the same message. VSTest's
count covers frameworks we don't instrument, and the module counts cover
runners that don't report one, such as Microsoft.Testing.Platform under
`dotnet test` on SDK 9 and earlier, where MTP projects share the CLI's
session with VSTest ones. Both senders use
`TestSession.TrySendExecutedTests`, which retries a full channel for up
to a second.
- The hook finds the session with the same lookup the Coverlet and
Microsoft CodeCoverage integrations use. Each of them had a private
copy, and `DotnetCommon` repeated it inline twice, so it now lives once
in `DotnetCommon.TryGetParentSessionSpanId`.

Compared with #9325:

- #9325 only recorded the count when the session was in the same process
as vstest.console, so `dotnet test` on SDK 9 and earlier never got the
new status.
- #9325 adds two hooks on `Microsoft.VisualStudio.TestPlatform.Client`,
a new target assembly that needs Honeypot and trimming entries, plus
per-request tracking with `ConditionalWeakTable`s. This PR has one hook
in vstest.console, which we already instrument.

## Test coverage

- `EmptyTestSessionTests`: zero, non-zero, missing, aborted, canceled
and failed runs, going through the real IPC path; zero reports from
every runner; a test module that ran tests keeps a session that VSTest
reported as empty passing, and one that ran none doesn't; a failed
session; a runner exception; a session without an IPC server. It mocks
`ITestOptimization` to skip the 5 s agent discovery, so each test takes
milliseconds.
- `VSTestEmptySessionTests` (integration, existing xUnit sample, real
vstest.console): a filter that matches nothing gives a skipped session,
and a matching test gives a passed one. With a parent session injected
through environment variables, vstest.console sends 0 or 1 to it; those
cases disable the xUnit integration, so the testhost's module doesn't
send its own count. Both of those cases fail if the hook doesn't send
the count. These tests skip for net8.0 to net10.0 on Linux and macOS
while CI uses the .NET 11 RC SDK, because .NET 11 RC can't share named
mutexes with .NET 8-10 (dotnet/runtime#134491). The SDK check that
`MsTestV2DiscoveryTests` already had now lives in
`TestingFrameworkEvpTest` so both classes share it. vstest.console runs
on the SDK, so the other target frameworks still cover the same code.
- Manual `dotnet test` runs with the profiler attached: on SDK 9 the
`dotnet` CLI session received the count and closed as skipped (0) or
passed (1), and on SDK 10 the vstest.console session did the same.
- Local runs on Linux with net8.0: the whole `Datadog.Trace.Tests.Ci`
namespace, the new integration tests, and the Release build of
`Datadog.Trace` with no warnings.

## Other details

- Known gaps:
- If a solution mixes VSTest and Microsoft.Testing.Platform projects
under `dotnet test` on SDK 9 or earlier, MTP projects that use a
framework we don't instrument don't send a count. If the VSTest projects
run no tests, the session can still be reported as skipped.
- A count is lost if the session's IPC channel stays full for more than
a second, and then another project's zero count could mark the session
as skipped. I didn't add a persisted fallback for that; the sender
retries a full channel for up to a second.
- `/Tests:` runs (`RunSpecificTestsArgumentExecutor`) aren't hooked and
stay passed.
- Not run locally: Windows, .NET Framework (vstest.console.exe) and
macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants